<template>
  <div>


    <div class="left-menu"
         :class="[isToggle?'toggle':'']"
         :style="{height:cavasHeight}">
      <div class="mask"></div>
      <div class="left-panel">
        <div class="head"><slot name="head"></slot></div>
        <div class="content"><slot name="content"></slot></div>
        <div class="tail"><slot name="tail"></slot></div>
      </div>
    </div>
  </div>
</template>
<style scoped>
  .left-menu{
    z-index: 10000;
    margin-left: -100%;
    height: 100%;
    width: 100%;
    transition: 0.5s;
    opacity: 0;
    position: absolute;
    top: 0px;
    left: 0px;
  }
  .mask{
    width: calc(100% - 210px);
    height: 100%;
    float: right;
  }
  .left-panel{
    background-color: aquamarine;
    height: 100%;
    width: 210px;
    -webkit-box-shadow: 5px 5px 5px rgba(0,0,0,0.2);
    -moz-box-shadow: 5px 5px 5px rgba(0,0,0,0.2);
    box-shadow: 5px 5px 5px rgba(0,0,0,0.2);
  }
  .left-menu.toggle{
    opacity: 1;
    transition: 0.5s;
    margin-left: 0px;
  }

  .left-menu .head{
    height: 30%;
    width: 100%;
  }
  .left-menu .content{
    height: 50%;
    width: 100%;
  }



</style>
<script>

export default{
  created(){
      console.log('created');

  },
  data(){
      return {
        isToggle: false
      }
  },
  computed:{
    cavasHeight: function(){
      let wh = document.body.clientHeight;
      return wh+'px';
    }
  },
  methods:{

      clickEvent(e){
        console.log('event:', e);
        if (e.pageX >= 200 && this.isToggle) {
          this.toggleMenu();
        }
      },

      toggleMenu(){
        if(this.isToggle){
          document.body.removeEventListener('click',this.clickEvent)
          this.isToggle= false;
        }
        else {
          document.body.addEventListener('click',this.clickEvent);
          this.isToggle = true;
        }
      }
  },
  destroy:{

  }

}
</script>
